Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements getopt for avr #9174

Closed
wants to merge 2 commits into from

Conversation

virajsahai
Copy link

Contribution description

Implemented getopt for atmega

Issues/PRs references

Fixes #3355

@virajsahai virajsahai force-pushed the getopt-added-atmega branch from ad35c17 to d8a6703 Compare May 24, 2018 01:48
@virajsahai virajsahai changed the title First getopt-atmega commit Implements getopt for avr May 24, 2018
Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying to tackle a quite old issue :)

I did a rough review of your change and you should reformat the files using uncrustify to be compliant with RIOT standards.
There are also other changes that are unrelated/not needed (mainly the removal of the stm32 header file).

.gitattributes Outdated
@@ -5,3 +5,5 @@
# when the heading is exactly 7 characters long.
*.md conflict-marker-size=100
*.txt conflict-marker-size=100
*.c text eof=lf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated. Please provide those files in a separate PR if really required on your side.

Copy link
Author

@virajsahai virajsahai May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do this to get LF after every line. Please do let me know if there is any other way of getting rid of the trailing whitespace error. Thanks!

char opt;
optarg = NULL;

if(optind < 1 || optind > argc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot's of style issues, you can run uncrustify to format your files with a RIOT compliant style.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! Thanks

extern "C" {
#endif

typedef struct{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct is not documented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry for being extra lost but I am fairly new to Open Source. I went through all the dev recommendations but didn't find the location where to document it?

int optopt;
} opt_t;

static const opt_t def_opt = {NULL,1,1,-1};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not documented

* @param[in] argv The array containing all the arguments.
* @param[in] optstring The string of expected options.
*
* @return ASCII value of the option if option was succesfully found, '?' or ':' when unknown option is found or argument is missing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long and should be split

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Thanks!

@@ -826,6 +826,7 @@ EXCLUDE_PATTERNS = */board/*/tools/* \
*/cpu/msp430_common/include/sys/*.h \
*/cpu/native/osx-libc-extra \
*/cpu/x86/include/* \
*/cpu/atmega_common/include/getopt.h \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

@miri64
Copy link
Member

miri64 commented May 24, 2018

Also, please provide a more telling commit message for your commit. It should tell what module got change and what the change entails (ideally <72 characters, at most 100). Our usual format would be something like

atmega_common: provide getopt support

Also nice to have (but not mandatory): some more detailed description about the change:

atmega_common: provide getopt support

libc-avr is lacking a `getopt` implementation. This change provides the
following feature set to provide basic `getopt` support

* ...

@virajsahai
Copy link
Author

@aabadie Thanks for all the helpful comments. I have fixed most issues. just need to document the struct. Please let me know where and how, couldn't find the relevant doc. Thanks!!

extern "C" {
#endif

typedef struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To document this, just add a doxygen @brief before the struct. Each attribute must be document as well. See here for an example.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for applying the changes fast @virajsahai.
I have found other minor things. See below.

Do you know a way for testing this ? Maybe @miri64 has an idea.

}
}
return c;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a missing newline at the end of this file.

* @param[in] argv The array containing all the arguments.
* @param[in] optstring The string of expected options.
*
* @return ASCII value of the option if option was succesfully found.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on successfully

* @param[in] optstring The string of expected options.
* @param[out] r The per call struct for holding return args and other options.
*
* @return ASCII value of the option if option was succesfully found.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on successfully

* @return ASCII value of the option if option was succesfully found.
* '?' or ':' when unknown option is found or argument is missing.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line can be removed

* @return ASCII value of the option if option was succesfully found.
* '?' or ':' when unknown option is found or argument is missing.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this blank line can be removed

@virajsahai virajsahai force-pushed the getopt-added-atmega branch 2 times, most recently from fa96102 to f21e76a Compare May 24, 2018 22:10
@virajsahai
Copy link
Author

virajsahai commented May 24, 2018

@aabadie i have done some generic testing with some edge cases but haven't done the real deal. It'd be great if someone can advise on that. Thanks!

@virajsahai
Copy link
Author

@miri64 @aabadie any updates??

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have done some generic testing with some edge cases but haven't done the real deal. It'd be great if someone can advise on that.

What do you mean with "generic testing" ? I don't know either how this could be tested. Pinging @miri64, maybe you have a better idea ?

Otherwise, I have remaining style comments, mainly because of too long lines that can be split to fit into 80 characters length.

* @file getopt.c
* @brief Implementation of getopt lib.
*
* This implements the getopt and getopt_r functionality. getopt_r has a few caveats, make sure to use it correctly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be split

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it should be removed, it's a copy-paste of the one in the header file.

return -1;
}

if (*argv[optind] != '-' || !(argv[optind] + 1) || *(argv[optind] + 1) == '\0' || *(argv[optind] + 1) == '-') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be split

return -1;
}

if (*argv[r->optind] != '-' || !(argv[r->optind] + 1) || *(argv[r->optind] + 1) == '\0' || *(argv[r->optind] + 1) == '-') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be split

* @file header
* @brief Implementation of getopt lib.
*
* This implements the getopt and getopt_r functionality. getopt_r has a few caveats, make sure to use it correctly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be split

/*INIT_OPT_T_PTR is used to initalize an opt_t* variable, INIT_OPT_T for opt_t. */
/*To change options, edit the fields of opt_t and call getopt_r*/

#define INIT_OPT_T_PTR &(opt_t){ NULL, 1, 1, -1 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those defines should be documented

@miri64
Copy link
Member

miri64 commented May 29, 2018

@aabadie i have done some generic testing with some edge cases but haven't done the real deal. It'd be great if someone can advise on that. Thanks!

Not sure why I specifically was summoned for this, but if you have test cases, please provide them as an application in tests/.

@aabadie
Copy link
Contributor

aabadie commented May 29, 2018

Not sure why I specifically was summoned for this

because you opened #3355 ;)

@virajsahai virajsahai force-pushed the getopt-added-atmega branch from f21e76a to 7b25b9d Compare May 29, 2018 21:32
@virajsahai virajsahai force-pushed the getopt-added-atmega branch from 7b25b9d to c35577c Compare May 29, 2018 21:36
@virajsahai
Copy link
Author

@aabadie by generic testing, I meant testing the logic completeness in edge cases. I don't know how to test after integrating.

@virajsahai
Copy link
Author

@aabadie any updates??

@aabadie
Copy link
Contributor

aabadie commented Jun 1, 2018

I meant testing the logic completeness in edge cases

I don't understand this, sorry. What edge cases ? How do you do that ? Do you have a RIOT specific application for that ?

@virajsahai
Copy link
Author

@aabadie No..i don't have a riot specific application for that. It would be great if you could point me to someone who can help with the testing.

And I tested the code as a regular c code on my pc..for cases when double colons are there..empty string passed etc.

@virajsahai
Copy link
Author

@aabadie any updates?

@aabadie
Copy link
Contributor

aabadie commented Jun 12, 2018

And I tested the code as a regular c code on my pc..for cases when double colons are there..empty string passed etc.

@virajsahai, I'm not sure but I think it would be nice to add a dedicated test application with shell and calls to the getopt function.
This way it will be possible to compare the versions provided by the different supported platforms. In this PR you provide a version for AVR, for ARM, I think the getopt from newlib is used. I don't know for MSP430 and others.
If getopt is not available for a given platform, it can be skipped using the BOARD_BLACKLIST environment variable in the Makefile.

It would be great to have other maintainers opinion on this. @gebart @kaspar030 @miri64 , what do you think ?

@PeterKietzmann PeterKietzmann added the Platform: AVR Platform: This PR/issue effects AVR-based platforms label Jun 20, 2018
@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@miri64
Copy link
Member

miri64 commented Aug 10, 2019

@jcarrano this somewhat coincides with your work in #9538. Can you have a look as well?

@stale stale bot removed the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@jcarrano
Copy link
Contributor

#9538 and this are not quite the same (#9538 does way more than getopt).

The question here is whether we seek to suport POSIX (or at least a reasonable subset). If we do, then regardless of #9538 this should go in.

@stale
Copy link

stale bot commented Feb 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Feb 13, 2020
@stale stale bot closed this Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: AVR Platform: This PR/issue effects AVR-based platforms State: stale State: The issue / PR has no activity for >185 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide getopt for platforms that don't support it
5 participants